package tq.com.tqteacher.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;

import tq.com.tqteacher.R;
import tq.com.tqteacher.model.TQPublishType;

public class TQNewPublishFragment extends Fragment {


    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_newpublish, container, false);

        v.findViewById(R.id.content).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(callback != null)callback.onCancle();
            }
        });

        v.findViewById(R.id.tb_icon).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(callback != null)callback.onPublish(TQPublishType.TYPE_TB);
            }
        });
        v.findViewById(R.id.dy_icon).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(callback != null)callback.onPublish(TQPublishType.TYPE_DY);
            }
        });

        v.findViewById(R.id.fxj_icon).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(callback != null)callback.onPublish(TQPublishType.TYPE_FXJ);
            }
        });

        v.findViewById(R.id.kj_icon).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(callback != null)callback.onPublish(TQPublishType.TYPE_KJ);
            }
        });

        v.findViewById(R.id.wk_icon).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(callback != null)callback.onPublish(TQPublishType.TYPE_WK);
            }
        });
        v.findViewById(R.id.pj_icon).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(callback != null)callback.onPublish(TQPublishType.TYPE_JP);
            }
        });

        v.findViewById(R.id.twjdy_icon).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(callback != null)callback.onPublish(TQPublishType.TYPE_TWDY);
            }
        });

        v.findViewById(R.id.qtfx_icon).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(callback != null)callback.onPublish(TQPublishType.TYPE_QTFX);
            }
        });

        v.findViewById(R.id.gglx_icon).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(callback != null)callback.onPublish(TQPublishType.TYPE_GGLX);
            }
        });

        return v;
    }

    @Override
    public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
        AlphaAnimation alphaAnimation ;
        if(enter){
            alphaAnimation = new AlphaAnimation(0, 1);
        }else{
            alphaAnimation = new AlphaAnimation(1, 0);
        }
        alphaAnimation.setRepeatCount(0);
        alphaAnimation.setDuration(250);

        return alphaAnimation;
    }

    private Callback callback;
    public void setCallback(Callback c){
        callback = c;
    }

    public interface Callback{
        void onCancle();
        void onPublish(int type);
    }
}
